package com.liuyk.commonlib.widget.contain;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.liuyk.commonlib.R;
import com.liuyk.commonlib.manager.ImageLoaderManager;
import com.liuyk.commonlib.utility.BitmapUtils;
import com.liuyk.commonlib.widget.navigation.BaseBottomNavigationItem;

/**
 * 首页导航栏子Item
 * <p>
 * Created by liuyakui on 2020/2/5.
 */
public class BottomNavigationItem extends BaseBottomNavigationItem<TablebarData> {

    private TextView name;
    private ImageView icon;
    private TextView bubble_hint;

    public BottomNavigationItem(Context context) {
        this(context, null);
    }

    public BottomNavigationItem(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BottomNavigationItem(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setOrientation(LinearLayout.HORIZONTAL);
    }

    @Override
    protected void onCreate() {
        name = findViewById(R.id.title);
        icon = findViewById(R.id.bottom_icon);
        bubble_hint = findViewById(R.id.bubble_hint);
    }

    @Override
    public int bottomNavigationItemResId() {
        return R.layout.app_bottom_navigation_item;
    }

    @Override
    public void renderItemView(int index, TablebarData dataBean) {
        if (!TextUtils.isEmpty(dataBean.name)) {
            name.setText(dataBean.name);
            name.setTextColor(dataBean.isSelect ? Color.parseColor(dataBean.selectColor) : Color.parseColor(dataBean.normalColor));
        } else {
            name.setVisibility(GONE);
        }

        if (!dataBean.isLocal) {
            ImageLoaderManager.loadImage(dataBean.isSelect ? dataBean.iconSel : dataBean.iconNor, icon);
        } else {
            icon.setImageBitmap(BitmapUtils.getAssetsBitmap(getContext(), dataBean.isSelect ? dataBean.iconSel : dataBean.iconNor));
        }
        if (dataBean.isBubbleHint) {
            bubble_hint.setVisibility(VISIBLE);
            bubble_hint.setText(dataBean.bubbleText);
        } else {
            bubble_hint.setVisibility(GONE);
        }
    }

}
